﻿using System.Web.Mvc;
using CodeContrib.Web.Routing;

namespace CodeContrib.Web.Mvc.Html
{
	public static class RouteLinkExtensions
	{
		public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string routeName)
		{
			return RouteLink(htmlHelper, innerHtml, routeName, null, null, null, null, null);
		}

		public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string routeName, object routeValues)
		{
			return RouteLink(htmlHelper, innerHtml, routeName, null, null, null, routeValues, null);
		}

		public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string routeName, object routeValues, object htmlAttributes)
		{
			return RouteLink(htmlHelper, innerHtml, routeName, null, null, null, routeValues, htmlAttributes);
		}

		public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, MvcHtmlString innerHtml, string routeName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)
		{
			var url = UrlHelper.GenerateUrl(routeName, null, null, protocol, hostName, fragment, routeValues.ToRouteValueDictionary(), htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, false /* includeImplicitMvcValues */);

			return htmlHelper.Link(innerHtml, url, htmlAttributes);
		}
	}
}